﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using MathLib.Common;

namespace MathLib.Algebra
{
    public struct Polynomial
    {
        public IEnumerable<Monomial> Monomials { get; set; }

        public static Polynomial Parse(string item)
        {
            Polynomial polynomial = new Polynomial();

            List<Monomial> monomials = new List<Monomial>();
            foreach (Match match in CompiledRegex.MonomialPattern.Matches(item))
            {
                monomials.Add(Monomial.Parse(match.Value));
            }
            polynomial.Monomials = monomials;

            return polynomial;
        }
    }
}